


$(function(){
    $('#login').on('click',function (e){
        e.preventDefault();
        $.ajax({
            type    : 'POST',
            url     : 'http://localhost:8080/signOn',
            data    : {
                login       : 'login',
                username    : $('#username').val(),
                password    : $('#password').val()
            },
            success : function (data){
                console.log('register ='+data);
                if(data.indexOf("Address") !== -1){
                    console.log(data);
                    window.location.href='http://localhost:8080/' + data.substring(data.indexOf(":") + 1, data.length);
                }else{
                    //显示
                    $('#error-msg').text(data);
                    console.log('register ='+data);
                }
            },
            error   : function (errorMsg){
                console.log(errorMsg);
            }
        });
    });
    $('#username').on('blur',function (){
        var username = $(this).val();
        if(username === ''){
            $('#error-msg').text('The username cannot be empty"');
        }else{
            $('#error-msg').text('');
        }
    });
    $('#password').on('blur',function (){
        var password = $(this).val();
        if(password === ''){
            $('#error-msg').text('The password cannot be empty"');
        }else{
            $('#error-msg').text('');
        }
    });
});